# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  
  def face_url(id)
    if User.find(id).face
      url_for(:controller=>'account', :action => 'face', :id =>User.find(id).face)
    else
      "/images/nobody.gif" 
    end
  end
  
  def face_big(id)
    "<img src='"+face_url(1)+"''width=85 height=85 border=1 alignt=center>"
  end
  
  def face_small(id)
    "<img src='"+face_url(1)+"''width=40 height=40 border=1 alignt=center>"
  end  
  
  def friendly_date(history)
    current=Time.now
    gap=(current-history).to_i
    if gap<60
      gap.to_s+" sec(s)"
    elsif gap<3600
      (gap/60).to_i.to_s+" min(s)"
    elsif gap<86400
      (gap/3600).to_i.to_s+" hr(s)"
    else
      (gap/86400).to_i.to_s+" dy(s)"
    end
  end
  
  def last_updater(user)
    face_small(user.id)+"<br>"+user.fullname
  end
  
end
